import AnswerLayout from '@/layouts/answer-layout/AnswerLayout.vue';
import BackLayout from '@/layouts/back-layout/BackLayout.vue';
import CreateLayout from '@/layouts/create-layout/CreateLayout.vue';
import DesignLayout from '@/layouts/design-layout/DesignLayout.vue';
import SettingLayout from '@/layouts/setting-layout/SettingLayout.vue';
import 'ant-design-vue';
import 'vue-router';
import { RouteRecordRaw } from 'vue-router';
import {
  ANSWER,
  ANSWERINDEX,
  ANSWERSUCCESS,
  BACK,
  BACKQUESTION,
  BACKUSER,
  CREATE,
  CREATECHOOSE,
  DESIGN,
  DESIGNQUEST,
  LOGIN,
  MANAGE,
  MANAGEDELETE,
  MANAGEMINE,
  ROUTE_403,
  ROUTE_404,
  SETTING,
  SETTINGANALYSIS,
  SETTINGANALYSISINDEX,
  SETTINGANALYSISSOURCE,
  SETTINGAPPEARANCE,
  SETTINGINDEX,
  SETTINGPUBLISH,
  SETTINGPUBLISHURL,
  USER,
  USERSET,
} from './route-name';
declare module 'vue-router' {
  interface RouteMeta {
    // 是可选的
    isAdmin?: boolean;
    // 每个路由都必须声明
    requiresAuth: boolean;
  }
}

// 静态路由
const staticRoutes: RouteRecordRaw[] = [
  {
    path: '/',
    redirect: '/login',
  },

  // 登录页 以及注册页
  {
    path: '/login',
    name: LOGIN,
    component: () => import('@/views/login/Login.vue'),
    meta: {
      requiresAuth: false,
    },
  },

  // 管理页
  {
    path: '/manage',
    name: MANAGE,
    component: BackLayout,
    meta: { requiresAuth: true },
    redirect: '/manage/mine',
    children: [
      {
        path: 'mine',
        name: MANAGEMINE,
        component: () => import('@/views/manage/ManagePage.vue'),
      },
      {
        path: 'delete',
        name: MANAGEDELETE,
        component: () => import('@/views/manage/ManageDeletePage.vue'),
      },
    ],
  },

  // 用户设置
  {
    path: '/user',
    name: USER,
    component: CreateLayout,
    meta: { requiresAuth: true },
    redirect: '/',
    children: [
      {
        path: 'setting',
        name: USERSET,
        component: () => import('@/views/user/UserContainer.vue'),
      },
    ],
  },

  // 新建过度
  {
    path: '/create',
    name: CREATE,
    component: CreateLayout,
    meta: { requiresAuth: true },
    redirect: '/create/choose',
    children: [
      {
        path: 'choose',
        name: CREATECHOOSE,
        component: () => import('@/views/create-temp/CreateTempPage.vue'),
      },
    ],
  },

  // 设计页
  {
    path: '/design',
    name: DESIGN,
    component: DesignLayout,
    meta: { requiresAuth: true },
    redirect: 'design/index',
    children: [
      {
        path: 'index',
        name: DESIGNQUEST,
        component: () => import('@/views/design/DesignPage.vue'),
      },
    ],
  },

  // 作答页面
  {
    path: '/answer',
    name: ANSWER,
    component: AnswerLayout,
    meta: { requiresAuth: false },
    redirect: '/answer/index',
    children: [
      {
        path: 'index',
        name: ANSWERINDEX,
        component: () => import('@/views/answer/AnswerPage.vue'),
      },
      {
        path: 'sucess',
        name: ANSWERSUCCESS,
        component: () => import('@/views/answer/AnwserSuccessPage.vue'),
      },
    ],
  },

  // 设置页
  {
    path: '/setting',
    name: SETTING,
    component: SettingLayout,
    redirect: '/setting/design',
    meta: {
      requiresAuth: false,
    },
    children: [
      {
        path: 'design',
        name: SETTINGINDEX,
        redirect: '/setting/design/appearance',
        component: () => import('@/views/setting/design/index.vue'),
        children: [
          // {
          //   path: 'index',
          //   name: SETTINGSETTING,
          //   component: () => import('@/views/setting/design/SettingPage.vue'),
          // },
          {
            path: 'appearance',
            name: SETTINGAPPEARANCE,
            component: () =>
              import('@/views/setting/design/SettingAppearancePage.vue'),
          },
        ],
      },
      {
        path: 'publish',
        name: SETTINGPUBLISH,
        redirect: '/setting/publish/url',
        component: () => import('@/views/setting/publish/index.vue'),
        children: [
          {
            path: 'url',
            name: SETTINGPUBLISHURL,
            component: () =>
              import('@/views/setting/publish/SettingPublichUrlPage.vue'),
          },
        ],
      },
      {
        path: 'analysis',
        name: SETTINGANALYSIS,
        redirect: '/setting/analysis/index',
        component: () => import('@/views/setting/analysis/index.vue'),
        children: [
          {
            path: 'index',
            name: SETTINGANALYSISINDEX,
            component: () =>
              import('@/views/setting/analysis/SettingAnalysisPage.vue'),
          },
          {
            path: 'source',
            name: SETTINGANALYSISSOURCE,
            component: () =>
              import('@/views/setting/analysis/AnalysisSourcePage.vue'),
          },
        ],
      },
    ],
  },

  // 后台管理静态页面
  {
    path: '/back',
    name: BACK,
    component: BackLayout,
    meta: { requiresAuth: false },
    redirect: '/back/user',
    children: [
      {
        path: '/back/user',
        name: BACKUSER,
        component: () => import('@/views/back-user/UserManagePage.vue'),
      },
      {
        path: '/back/question',
        name: BACKQUESTION,
        component: () => import('@/views/back-user/QuestionManagePage.vue'),
      },
    ],
  },

  //  404
  {
    path: '/404',
    name: ROUTE_404,
    component: () => import('@/views/tips/NotFoundPage.vue'),
    meta: {
      requiresAuth: false,
    },
  },

  {
    path: '/403',
    name: ROUTE_403,
    component: () => import('@/views/tips/NotFoundPage.vue'),
    meta: {
      requiresAuth: false,
    },
  },
];

export default staticRoutes;
